package cn.signalpha.modules.base.service;

import cn.signalpha.core.mp.base.BaseServiceImpl;
import cn.signalpha.core.tool.constant.SystemConstant;
import cn.signalpha.modules.base.entity.Nav;
import cn.signalpha.modules.base.mapper.NavMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

import static cn.signalpha.common.cache.CacheNames.EXPIRATION_TIME;
import static cn.signalpha.common.cache.CacheNames.NAV_KEY;

/**
 * 服务类
 *
 * @author signalpha
 */
@Service
public class NavService extends BaseServiceImpl<NavMapper, Nav> {

	@Cacheable(cacheNames = NAV_KEY, unless="#result==null")
	public List<Nav> listCache() {
		return list(Wrappers.<Nav>lambdaQuery().eq(Nav::getStatus, SystemConstant.DB_STATUS_NORMAL).orderByDesc(Nav::getSort));
	}

	@Cacheable(cacheNames = NAV_KEY + EXPIRATION_TIME, key = "#id")
	public Nav getByCache(Long id) {
		return getById(id);
	}

	@CacheEvict(cacheNames = NAV_KEY, allEntries = true)
	public void removeCaChe() {
	}

}

